<template>
	<div class="container">
		<div class="jx-container">
      <div class="jx-table">
        <div class="title">
          <img class="icon" src="/static/img/icon-platform.png"/>
          活动列表
          <div class="add-new">
            <el-button class="jx-btn" type="primary" @click="addRow">新增活动</el-button>
          </div>
        </div>
        <el-table :data="list" border style="width: 100%" v-loading="boo.loading">
          <el-table-column type="index" label="序列" width="60" align="center">
            <template slot-scope="scope">
              <span>{{(scope.$index + 1) + ((params_list.page - 1) * params_list.size)}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="activityImgUrl" label="引导图" width="130" align="center">
            <template slot-scope="scope">
              <img class="logo" :src="scope.row.activityImgUrl"/>
            </template>
          </el-table-column>
          <el-table-column prop="activityTitle" label="名称" width="150" align="center" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <el-button @click="viewRow(scope.row)" type="text" size="small">{{scope.row.activityTitle}}</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="activityCatalog" label="活动类型" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="activityUrl" label="活动链接" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="time" label="活动时间" align="center" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{scope.row.activityBeginAt}}</span>&nbsp;&nbsp;~<br/>
              <span>{{scope.row.activityEndAt}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="activityArea" label="活动地区" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="activityLimitCount" label="活动商家数" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column prop="activityRequires" label="报名要求" align="center" :show-overflow-tooltip="true">
          </el-table-column>
          <el-table-column label="报名详情" width="210" align="center">
            <template slot-scope="scope">
              <span>待审核：<span class="red">{{scope.row.activityApprovalCount}}</span></span><br/>
              <span>报名：<span class="red">{{scope.row.activityApplyCount}}</span></span>
              <span>通过：<span class="red">{{scope.row.activityApprovedCount}}</span></span>
              <span>不通过：<span class="red">{{scope.row.activityUnapprovedCount}}</span></span>
            </template>
          </el-table-column>
          <el-table-column prop="activityStatus" label="活动装填" align="center">
          </el-table-column>
          <el-table-column label="操作" width="160" align="center">
            <template slot-scope="scope">
              <el-button @click="viewRow(scope.row)" type="text" size="small">查看详情</el-button>
              <el-button v-if="scope.row.activityStatus == '进行中'" @click="hiddenRow(scope.row)" type="text" size="small">终止</el-button>
              <el-button v-if="scope.row.activityStatus == '未开始'" @click="deleteRow(scope.row)" type="text" size="small">取消活动</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div v-if="list.length != 0" class="jx-pagination">
          <el-pagination @current-change="pageChange" @size-change="handleSizeChange" :current-page="params_list.page" :page-sizes="[10,50,100]" :page-size="params_list.size" layout="total, sizes, prev, pager, next, jumper"
            :total="other.allRow">
          </el-pagination>
        </div>
      </div>
    </div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
        https: this.$api.promotion.active,
        boo: {
          loading: false,
        },
        other: {
          allRow: 1,
        },
        list: '',
        params_list: {
          page: 1,
          size: 10,
          name: '',
        },
			}
		},
		mounted(){
      let _self = this
      _self.getList()
    },
		methods: {
      getList(){
        let _self = this
        let params = {
          pageNumber: _self.params_list.page,
          pageSize: _self.params_list.size,
          orderBy: '',
        }
        _self.boo.loading = true
        let success = (res)=>{
          res = res.data
          if(res.retCode == 1){
            _self.list = res.retObject.list
            _self.other.allRow = Number(res.retObject.totalRow)
          }else{
            _self.$message.error(res.retMsg)
          }
          _self.boo.loading = false
        }
        _self.$axios.get(_self.https.list, params, success) 
      },
      pageChange(val){
        let _self = this
        _self.params_list.page = val
        _self.getList()
      },
      handleSizeChange(val) {
        let _self = this
        _self.params_list.size = val
        _self.getList()
      },
      addRow(){
        let _self = this
        let params = {
          path: '/promotion/detail/new_active',
        }
        _self.$router.push(params.path)
      },
      hiddenRow(){
        
      },
      viewRow(item){
        let _self = this
        let params = {
          path: '/promotion/detail/active_detail?id=',
          query: item.id + '&type=' + item.activityCatalog
        }
        _self.$router.push(params.path + params.query)
      },
      deleteRow(){

      }
    }
	}

</script>
<style scoped lang="sass">
  .jx-table
    /deep/ .el-table__body td
      .cell
        height: auto
        line-height: auto
</style>
